package utils

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

const (
	success           = 2000
	FailedError       = 4000
	CheckTookError    = 5000
	CreateTookError   = 5001
	LoginError        = 10000
	UserInfoError     = 10001
	UPPhotographError = 10002
	UPFIleError       = 10003
	DeleteError       = 10004
	UPDATAError       = 10005
	ReadError         = 10006
)

type ReturnMsg struct {
	Total int64       `json:"total"`
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
}

func general(ctx *gin.Context, code int, Total int64, Msg string, Data interface{}) {
	resp := &ReturnMsg{
		Total: Total,
		Code:  code,
		Msg:   Msg,
		Data:  Data,
	}
	ctx.JSON(http.StatusOK, resp)
}

func Successful(ctx *gin.Context, Total int64, Data interface{}) {
	general(ctx, 2000, Total, "success", Data)
}

func Failed(ctx *gin.Context, Data interface{}) {
	general(ctx, 4000, 0, "failed", Data)
}
